//
//  RJCheckBottomCell.m
//  AirQuality
//
//  Created by Po on 15/3/13.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJCheckBottomCell.h"
#import "AppDelegate.h"

@implementation RJCheckBottomCell

- (void)awakeFromNib {
    // Initialization code
}

//创建自定义cell
+ (instancetype)bottomWithTableView:(UITableView *)tableView
{
    static NSString * resuId = @"RJCheckBottomCell";
    RJCheckBottomCell * cell = [tableView dequeueReusableCellWithIdentifier:resuId];
    if (!cell) {
        cell = [[RJCheckBottomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resuId];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
//创建子控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //站点
        CGFloat centerX = ScreenWidth/4;
        UILabel * lable = [[UILabel alloc] initWithFrame:CGRectMake1(10, 0, 70, 70)];
        _position = lable;
        _position.numberOfLines = 0;
        _position.textAlignment = NSTextAlignmentCenter;
        _position.textColor = GetRGBColor(84, 84, 84, 1);
        [self.contentView addSubview:_position];
        //AQI
        UILabel * aqiLab = [[UILabel alloc] initWithFrame:CGRectMake1(0, 0, 60, 30)];
        _aqiValue = aqiLab;
        _aqiValue.center = CGPointMake(centerX*3/2, 35);
        _aqiValue.numberOfLines = 0;
        _aqiValue.layer.cornerRadius = 5.0;
        _aqiValue.layer.masksToBounds = YES;
//        _aqiValue.backgroundColor = [UIColor blueColor];
        _aqiValue.textAlignment = NSTextAlignmentCenter;
        _aqiValue.textColor = GetRGBColor(84, 84, 84, 1);
        [self.contentView addSubview:_aqiValue];
        //MAX
//        CGFloat maxX = CGRectGetMaxX(_aqiValue.frame);
        UILabel * maxLab = [[UILabel alloc] initWithFrame:CGRectMake1(0, 0, 80, 50)];
        _maxValue = maxLab;
        _maxValue.numberOfLines = 0;
        _maxValue.center = CGPointMake(centerX*5/2, 35);
//        _maxValue.backgroundColor = [UIColor redColor];
        _maxValue.textAlignment = NSTextAlignmentCenter;
        _maxValue.textColor = GetRGBColor(84, 84, 84, 1);
        [self.contentView addSubview:_maxValue];
        //MIN
        UILabel * minLab = [[UILabel alloc] initWithFrame:CGRectMake1(0, 0, 80, 50)];
        _minValue = minLab;
        _minValue.center = CGPointMake(centerX*7/2, 35);
        _minValue.numberOfLines = 0;
//        _minValue.backgroundColor = [UIColor greenColor];
        _minValue.textAlignment = NSTextAlignmentCenter;
        _minValue.textColor = GetRGBColor(84, 84, 84, 1);
        [self.contentView addSubview:_minValue];
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
//设置背景色
- (void)setDataValue:(NSString *)value type:(NSString *)type backgroundColorWithValur:(NSString *)iValue
{
    [_aqiValue setText:[NSString stringWithFormat:@"%@",value]];
    if ([type isEqualToString:@"co"]) {
        float coVal = [value floatValue];
        NSString * coValStr = [NSString stringWithFormat:@"%.1f",coVal];
        _aqiValue.text = coValStr;
    }
    [_aqiValue setTextColor:[UIColor blackColor]];
    NSString * trueKey = [RJTools getTrueTypeTitlleWithCellKey:type];
    NSString * InumStr ;
    InumStr = [type isEqualToString:@"aqi"] ?value:iValue;
    if ([InumStr isKindOfClass:[NSNull class]]) {
        InumStr = @"300";
    }
    [_aqiValue setBackgroundColor:[RJTools getColorWithAirINum:[InumStr floatValue]]];
    if ([value isEqualToString:@"—"]) {
        [_aqiValue setBackgroundColor:[UIColor grayColor]];
    }
}
CG_INLINE CGRect
CGRectMake1(CGFloat x, CGFloat y, CGFloat width, CGFloat height)

{
    AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
    CGRect rect;
    rect.origin.x = x * myDelegate.autoSizeScaleX; rect.origin.y = y * myDelegate.autoSizeScaleY;
    rect.size.width = width * myDelegate.autoSizeScaleX; rect.size.height = height * myDelegate.autoSizeScaleY;
    return rect;
}
@end
